package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportAddressEdit;
import cn.stylefeng.guns.modular.transport.mapper.TransportAddressEditMapper;
import cn.stylefeng.guns.modular.transport.model.params.TransportAddressEditParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportAddressEditResult;
import  cn.stylefeng.guns.modular.transport.service.TransportAddressEditService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 地址修改申请表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-11-21
 */
@Service
public class TransportAddressEditServiceImpl extends ServiceImpl<TransportAddressEditMapper, TransportAddressEdit> implements TransportAddressEditService {

    @Override
    public void add(TransportAddressEditParam param){
        TransportAddressEdit entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportAddressEditParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportAddressEditParam param){
        TransportAddressEdit oldEntity = getOldEntity(param);
        TransportAddressEdit newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportAddressEditResult findBySpec(TransportAddressEditParam param){
        return null;
    }

    @Override
    public List<TransportAddressEditResult> findListBySpec(TransportAddressEditParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportAddressEditParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportAddressEditParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportAddressEdit getOldEntity(TransportAddressEditParam param) {
        return this.getById(getKey(param));
    }

    private TransportAddressEdit getEntity(TransportAddressEditParam param) {
        TransportAddressEdit entity = new TransportAddressEdit();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
